package com.hitcoder.chat.ui.widget

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Typeface
import android.util.AttributeSet
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import com.hitcoder.chat.R

/**
 * iconfont矢量图控件
 */
class IconfontTextView : AppCompatTextView {
    var iconfontPatin: String? = null

    @SuppressLint("CustomViewStyleable")
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.IconfontButton)
        iconfontPatin = typedArray.getString(R.styleable.IconfontButton_iconfont)
        init(context)
        typedArray.recycle()
    }

    constructor(context: Context) : super(context) {
        init(context)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        init(context)
    }

    private fun init(context: Context) {
        typeface = Typeface.createFromAsset(context.assets, iconfontPatin)
    }
}